<?php
  
  
  /* 我发的红包*/
function my_send_red_bag(){
    global $db; 
    global $web_url ;
    $usersid=$_SESSION['usersid'];
    $arrRet = array('cmd'=>'','msg'=>'');  
    if(!isset($_SESSION['usersid'])) {
        $arrRet['cmd'] = "err";
        $arrRet['msg'] = "登录超时!";
        echo json_encode($arrRet);
        exit();
    }
    $jq='$';   
    $RetContent="
    <script type='text/javascript' src='js/agent.js'></script>
        <div class='message   recharge'>
        <div class='r_nav'>
            <img src='img/banner.png' />
            <p class='title'>发红包</p>
            <p class='cen'>发起红包,收获红包查询</p>
        </div>
		<div class='r_list_t'>
			<ul>
				<li ><a href="javascript:getContent('smbinfo.php','red_bag')">发起红包</a></li>
				<li ><a href="javascript:getContent('smbinfo.php','my_receive_red_bag')">我收到的红包</a></li>
				<li class='pitch'><a href="javascript:getContent('smbinfo.php','my_send_red_bag')">我发的红包</a></li>
			</ul>
		</div>
		<div class='list recharge_log_list'>
			<table class='table_list ' cellspacing='0px' style='border-collapse:collapse;'>
				<tr height='30'>
					<th  style='130px  !important;'  align='left'>红包名</th>
					<th>抢得时间</th>    
					<th width=70  align='left'>金额</th>
					<th >红包类型</th> 
					<th >发起人</th>
					<th align='left'  >留言</th>
				</tr>
				".Get_My_recv_Red_Bag()."
			</table>
		</div>
    </div>";
    echo $RetContent;
}
    

  
  
  
//我收到的红包
function Get_My_recv_Red_Bag()
{
    global $db;
    $page = isset($_POST['page'])?$_POST['page']:1;
    if(!isset($_SESSION['usersid'])) {
        $arrRet['cmd'] = "timeout";
        return $arrRet['cmd'];
    }
    $userid =$_SESSION['usersid'];
    $pagesize = 15;
    $RetContent="";
    //表内容
    $sql = "select  recv_time,recv_msg,r.points,nickname,u.id,bagtype,send_title
    from  redbag_recv_log r
	LEFT JOIN redbag_send_log s on(r.bagno=l.bagno)
	LEFT JOIN users u  on(u.id=s.send_uid)
    where  r.recv_uid='{$userid}' and r.state=1 
	";
    $TotalRecCount = $db->GetRecordCount($sql);

    $sql=$sql." order by id desc ";
    $sql .= GetLimit($page,$pagesize); 
    $result =  $db->query($sql);
    while($rs=$db->fetch_array($result)){
        $rs['send_title']=ChangeEncodeG2U($rs['send_title']);
		$rs['recv_msg']=ChangeEncodeG2U($rs['recv_msg']);
		$rs['nickname']=ChangeEncodeG2U($rs['nickname'])."(".$rs['id'].")";
        if($rs['bagtype']==0){
            $rs['bagtype']='普通红包';
        }else{
            $rs['bagtype']='手气红包';
        }
        $rs['points']= number_format($rs['points'])."(￥".number_format($rs['points']/1000,2).")";
 
        $RetContent .= "
            <tr>
                <td style='width:160px!important;'>{$rs['send_title']}</td>
                <td>{$rs['points']}</td>
				<td style='width:50px!important;'>{$rs['bagtype']}</td>
                <td style='width:20px!important;'>{$rs['nickname']}</td>
                <td style='width:50px!important;'>{$rs['recv_time']}</td>
                <td>{$rs['recv_msg']}</td>
          </tr>";
    }

    //分页
    if($TotalRecCount > $pagesize)
    {
        $divPage = "<div class='pagediv'></div><div class='Paging'>\r\n";
        require_once('inc/fenye.php');
        $ajaxpage=new page(array('total'=>$TotalRecCount,'perpage'=>$pagesize,'ajax'=>"ajax_page_my_send_red_bag",'nowindex' => $page));
        $divPage .= $ajaxpage->show();
        $divPage .= "</div>\r\n";
        $RetContent .= "<tr><td colspan=6>".$divPage."</td></tr>";
    }
    return $RetContent;
}